package com.haoshuang.zhouzhoubang.ui.page.mine.settings

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.AppVersionBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class SettingsViewModel : BaseViewModel() {

    // 注销账号
    val getData6 = StatefulMutableLiveData<Any>()
    fun getData6(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/master/del_master", *params,
                onStart = {
                    getData6.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData6.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData6.value = StateData.Success(it)
                })
        }
    }

    /**
     * 设置短信通知开关
     */
    val setNoteData = StatefulMutableLiveData<Any>()
    fun setNote(isNote: Int) = netRequest {
        start { setNoteData.value = StateData.Loading }
        request { ApiRepo.setNote(isNote)  }
        success { setNoteData.value = StateData.Success(it.data) }
        error { code, msg ->
            setNoteData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 获取版本信息
     */
    val getAppVersionsData = StatefulMutableLiveData<AppVersionBean>()
    fun getAppVersions() = netRequest {
        start { getAppVersionsData.value = StateData.Loading }
        request { ApiRepo.getAppVersions()  }
        success { getAppVersionsData.value = StateData.Success(it.data) }
        error { code, msg ->
            getAppVersionsData.value = StateData.Error(code, msg)
        }
    }
}